package com.gitee.wsl.concurrent.api.cancel

//import org.jetbrains.annotations.NonBlocking

fun interface Cancellable{

    //@NonBlocking
    fun cancel()

    companion object{
        val EMPTY:Cancellable = Cancellable{}
    }

}

/**
 * Represents a forward reference to a [Cancellable] that was already
 * registered and needs to be filled in later.
 *
 *
 * **INTERNAL API:** Internal apis are subject to change or removal
 * without any notice. When code depends on internal APIs, it is subject to
 * breakage between minor version updates.
 */

fun interface CancellableForwardRef : Cancellable {
    fun set(cancellable: Cancellable)

    override fun cancel() {}
}

fun Cancellable.doOnCancel(block: () -> Unit): Cancellable =
    Cancellable {
        this@doOnCancel.cancel()
        block()
    }
